import React, { Component } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'

export default class RouterView extends Component {
    static defaultProps = {
        routes: []
    }
    render() {
        const { routes } = this.props
        return (
            <Switch>
                {
                    routes.length && routes.map((item, index) => {
                        return item.path ? <Route key={index} path={item.path} render={(props) => <item.component {...props} routes={item.children} />} />
                            : <Redirect key={index} to={item.to} exact from={item.from} />
                    })
                }
            </Switch>
        )
    }
}
